package com.ws.operator;
/*
三元运算符
1.结构：(条件表达式)? 表达式1 : 表达式2
2.说明
①条件表达式的结果为 boolean 类型
②根据条件表达式真或假，决定执行表达式1或2
 */
public class TernaryTest {
    public static void main(String[] args) {

        //获取两个整数的较大值
        int m = 0;
        int n = 1;
        int x = 2;

        int max = Math.max(m, n);
        int max2 = m > n ? m: n;
        System.out.println(max2);

        String maxStr = m > n ? "m大" : n == m ? "m和n相等": "n大";
        System.out.println(maxStr);

        String str = m == 0 ? "老板":m == 1 ? "经理":"员工";
        System.out.println(str);


        //获取三个数中的最大值
        int n1 = 12;
        int n2 = 11;
        int n3 = 13;

        int maxN = ((n1 > n2 ? n1 : n2) > n3 ? n2 : (n3 > n1 ? n3 : n1));
        System.out.println(maxN);

        int maxN2 = n1 > n2 ? n1 : n2;
        int maxN3 = maxN2 > n3 ? maxN2 : n3;
        System.out.println(maxN3);

    }
}
